# %%
# 导入包
import cv2
import matplotlib.pyplot as plt
import numpy as np

# 导入视频
input_video = {}
# 下载好的视频文件
input_video['vc'] = cv2.VideoCapture('video_30.mp4')
# 判断是否读取成功
if input_video['vc'].isOpened():
    # Python语法，元组读取
    input_video['open'] = input_video['vc'].read()
else:
    input_video['open'] = False
    
# 循环帧读取，两个退出条件：视频播放完/输入'ESC'退出
while input_video['open']:
    open,frame = input_video['vc'].read()
    if frame is None:
        break;
    if open:
        # 我们先播放灰度图像
        gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
        # 打开一个名为result的窗口，播放帧
        cv2.imshow('result',gray)
        # 这个是特殊组合，waiteKey指每帧的时间，输入'esc'退出视频播放
        if cv2.waitKey(10) & 0xff == 27:
            break;
        
# 释放视频输入流
input_video['vc'].release();
# 关闭所有窗口
cv2.destroyAllWindows();



